using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace PicturePage
{
    public partial class PictureSettings : Form
    {
        private Configuration config;

        public PictureSettings(Configuration configuration)
        {
            InitializeComponent();

            config = configuration;
            numColumns.Value = (decimal)config.Columns;
            numRows.Value = (decimal)config.Rows;
            chkLinkedImages.Checked = config.MakeLinkedImages;
            numThumbnailHeight.Value = (decimal)config.ThumbnailHeight;
            numThumbnailWidth.Value = (decimal)config.ThumbnailWidth;
            numLinkedHeight.Value = (decimal)config.LinkedImageHeight;
            numLinkedWidth.Value = (decimal)config.LinkedImageWidth;

            if (config.PictureAlign == rdbCenter.Text)
                rdbCenter.Checked = true;
            else if (config.PictureAlign == rdbLeft.Text)
                rdbLeft.Checked = true;
            else if (config.PictureAlign == rdbRight.Text)
                rdbRight.Checked = true;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            config.Columns = (int)numColumns.Value;
            config.Rows = (int)numRows.Value;
            config.MakeLinkedImages = chkLinkedImages.Checked;
            config.ThumbnailWidth = (int)numThumbnailWidth.Value;
            config.ThumbnailHeight = (int)numThumbnailHeight.Value;
            config.LinkedImageWidth = (int)numLinkedWidth.Value;
            config.LinkedImageHeight = (int)numLinkedHeight.Value;

            if (config.PictureAlign == rdbCenter.Text)
                rdbCenter.Checked = true;
            else if (config.PictureAlign == rdbLeft.Text)
                rdbLeft.Checked = true;
            else if (config.PictureAlign == rdbRight.Text)
                rdbRight.Checked = true;

            Configuration.Serialize("config.xml", config);

            this.DialogResult = DialogResult.OK;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            this.lblLinked.Visible = this.chkLinkedImages.Checked;
            this.lblLinkedX.Visible = this.chkLinkedImages.Checked;
            this.numLinkedHeight.Visible = this.chkLinkedImages.Checked;
            this.numLinkedWidth.Visible = this.chkLinkedImages.Checked;
        }
    }
}